<template>

    <button type="button" @click="save(item)">
      {{ item.showInput ? "保存" : "修改" }}
    </button>
    <button type="button" @click="deldata(item.id)">删除</button>
  

</template>

<script setup>
// import {defineEmits} from "vue"
// import { FetchFunc } from "../request/http"
import { edit,del } from "../request/todolist"
const props=defineProps({
item:{
  type:Object,
  default:()=>{}
}
})

const emit=defineEmits(['reset','refresh'])
const save=(itemObj)=>{
emit('reset')
editData(itemObj)
}



const editData=async (itemObj)=> {
debugger
if (itemObj.showInput) {

itemObj.showInput = false;

await edit(itemObj)

} else {

itemObj.showInput = true;
}

//localStorage.setItem("mylist", JSON.stringify(listdata.value));
}


const deldata =async (id) => {
//console.log(index)

if (confirm("真的要删除吗?")) {


const result=await del(id)

if(result){

emit('refresh')
}


}
};
</script>

<style lang="scss">

</style>